/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Example_08_Collections.java]
 * Creation Date        [02-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_06_collections;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 集合框架java.util.Collections
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Example_08_Collections {

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {

		// 创建一个包含100个元素的集合
		List<String> list1 = Collections.nCopies(100, "Default");
		System.out.println("list1 size === " + list1.size());

		Set<String> singletonSet = Collections.singleton("Default");
		System.out.println("singletonSet size === " + singletonSet.size());

		List<Integer> list = new ArrayList<Integer>();
		list.add(5);
		list.add(3);
		list.add(1);
		list.add(8);
		list.add(15);
		list.add(6);
		list.add(22);
		list.add(9);

		// Collections中的排序方法
		Collections.sort(list);

		// 找到集合中的最大最小值
		System.out.println(Collections.max(list));
		System.out.println(Collections.min(list));

		// 逆序集合
		Collections.reverse(list);

		// 数组转换为集合
		String[] values = { "one", "two", "three" };
		HashSet<String> set = new HashSet<String>(Arrays.asList(values));
		System.out.println(set);

		// 集合转换为数组
		values = set.toArray(new String[0]);
		System.out.println(Arrays.toString(values));

	}

}
